<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="org.miku.db.*" %>
<%@ page import="org.miku.module.note.*" %>
<%
	int currentPage = 0;
	List<NoteInfo> noteList = null;
	
	String temp = request.getParameter("page");
	if(temp != null) {
		try{
			currentPage = Integer.parseInt(temp);
		}catch(NumberFormatException ex) {
			ex.printStackTrace();
		}
	}
	
	SQLHelper sqlHelper = new SQLHelper(
			SQLConnectionInfo.DB_MYSQL_HOST,
			SQLConnectionInfo.DB_MYSQL_PORT,
			SQLConnectionInfo.DB_MYSQL_DATABASE,
			SQLConnectionInfo.DB_MYSQL_USER,
			SQLConnectionInfo.DB_MYSQL_PASSWORD);
	if(sqlHelper.isReady()) {
		NoteManager noteManager = new NoteManager(sqlHelper);
		PageManager pageMgr = new PageManager(noteManager, currentPage);
		
		noteList = pageMgr.getData();
		if(noteList == null) {
%>
		<!-- 无内容可显示 -->
<%
		} else {
			out.println("<ul>");
			for(int i = 0, count = noteList.size(); i < count; i++) {
%>
				<li><%=noteList.get(i).getNoteId() %></li>
				<li><%=noteList.get(i).getAuthor() %></li>
				<li><%=noteList.get(i).getTitle() %></li>
				<li><%=noteList.get(i).getContent() %></li>
				<li><%=noteList.get(i).getCreateTime() %></li>
				<li><%=noteList.get(i).getModifyTime() %></li>
<%
				out.println("</ul>");
				// pageMgr.getPageCount(); 获取总页数
				// currentPage 当前页面索引
			}
		}
		
		sqlHelper.close();
	}
%>
<!--
  2014年12月28日 20:37:18
-->
<html>
<head>
<title>online-note</title>
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Styles-->
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-theme.css">
<link rel="stylesheet" href="css/index.css">

</head>
<body>
    <!-- Nav -->
    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div id="navBar" class="container">
        <div class="navbar-header visible-xs" data-toggle="collapse" data-target="#top-nav">
          <a class="navbar-brand" href="#">Online-Note</a>
        </div>
        <div class="navbar-header hidden-xs">
          <a class="navbar-brand" href="#">Online-Note</a>
        </div>
        <div id="top-nav" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="navli nav-top-home">
              <a href="#" id="brandLogo" langid="nav-home">Home</a>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Language <b class="caret"></b></a>
              <ul id="LangList" role="menu" class="dropdown-menu">
                <li class="resetLang" data-id="en">
                 <a href="#">English</a>
                </li>
                <li class="resetLang" data-id="cn">
                  <a href="#">简体中文</a>
                </li>
                  <li class="resetLang" data-id="zh">
                  <a href="#">繁體中文</a>
                </li>
                  <li class="resetLang" data-id="ja">
                  <a href="#">日本語</a>
                </li>
                  <li class="resetLang" data-id="ko">
                  <a href="#">韓語</a>
                </li>
                  <li class="resetLang" data-id="ru">
                  <a href="#">Pусский</a>
                </li>
                  <li class="resetLang" data-id="uk">
                  <a href="#">Українська</a>
                </li>
              </ul>
            </li>
          </ul>
          <div class="searchNav nav navbar-nav navbar-right input-group">
            <form action="/mirror/search" id="srchForm" class="navbar-form">
              <div class="input-group">
                <label style="display: inline">
                <input name="keyword" class="form-control search-animate" id="srch-term" langid="mirror-srch-box" placeholder="Search..." value="">
                </label>
                <div class="input-group-btn">
                  <button class="btn btn-primary" type="submit" style="height: 34px;">
                    <span class="glyphicon glyphicon-search"></span>
                  </button>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
	  
	<div class="container">
      <!-- login -->
      <!-- The new form has been created, 
        please add action and name values !
        please add action and name values !
        please add action and name values !
      -->
      <form action="" id="form" method="post" onSubmit="return validate1()" class="form-signin" role="form">
        <h3 class="form-signin-heading">登陆</h3>
        <input type="username" name="" class="form-control" placeholder="用户名" required autofocus>
        <input type="password" name="" class="form-control" placeholder="密码" required>
    		<div class="password-error-box" type="password-error-box">
    			<!-- the password error cue will input here-->
    		</div>
        <div class="checkbox">
          <label>
            <input type="checkbox" value="remember-me"> 记住我
          </label>
          <div class="forget" style="">
            <a href="baidu.com" title="">忘记密码?</a>    
          </div>
        </div>

        <div class="loginbuttom">
        	<button class="btn btn-lg btn-primary" type="submit" value="登录">登陆</button>
        	<button class="btn btn-lg btn-default" type="button" value="注册" onclick="window.location.href='register.jsp'">注册</button>
        </div>
      </form>

    </div> <!-- /container -->
	<button id="btn1">error_msg_fadein  test &nbsp;</button><br>
  <button id="btn2">error_msg_fadeout test</button>

  <div class="test">
    <input type="text" name="" value="" placeholder="search-input-animate-test">
  </div>
  
	<!--  the old form
	<center>
		<form action="login_check.jsp" id="form" method="post"
			onSubmit="return validate1()">
			<table border="10">
				<h1>
					<font color="green">登录操作</font>
					<h1>
						<hr>
						<tr>
							<td>登录名：</td>
							<td><input type="text" name="uname">
							</td>
						</tr>

						<tr>
							<td>密码：</td>
							<td><input type="password" name="psd">
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<input type="submit" value="登录"> 
								<input type="reset" value="重置"> 
								<input type="button" value="注册" onclick="window.location.href='register.jsp'">
						</tr>
			</table>
		</form>
	</center>
	-->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">

    //验证错误事件
    function password_error_event () {

    }
    
	 //错误信息
    $(document).ready(function error_msg_fadein(){

        $("#btn1").click(function(){
            $("[type='password-error-box']").prepend(
                "<div class=\"login-error\" id=\"login-error\" type=\"login-error-div\">" + 
                "<p>" + 
                "用户名 或 密码 验证失败，请重试!" + 
                "</p>" + 
                "</div>"
            );
        });
    });

    //错误信息淡出
	$(document).ready(function error_msg_fadeout(){

		$("div[class='container'], div[type='password-error-box'], input[type='username'], input[type='password'], #btn2").click(function(){
			$("[type='login-error-div']").fadeOut(800);
		});
	});
		
	
    
  //JS验证空表单
    function validate1(){
    var uname=document.forms[0].uname.value;
    var password=document.forms[0].psd.value;
      if(uname.length<=0){
      	alert("用户名不能为空，请输入用户名！");
      	return false;
      }
      else if(password.length<=0){
      	alert("密码不能为空，请输入密码！");
      	return false;
      }
      else{
      	return true;
      }
    }
    </script>

</body>
</html>